home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Pascal / Applications / NIH Image 1.59 / Macros / Editing Macros < prev    next >
Encoding:
Text File  |  1995-06-27  |  6.4 KB  |  88 lines  |  [TEXT/Imag]

  1. var {Global variable, initially zero}
  2.   RoiLeft,RoiTop,RoiRight,RoiBottom:integer;
  3.  
  4. macro 'Show Tools [T]';
  5. begin
  6.   SelectWindow('Tools');
  7. end;
  8.  
  9. Macro 'Draw Arrow [A]'
  10. {Draws an arrow based on the current straight line selection.}
  11. var
  12.   size,angle,dx,dy,pi,theta:real;
  13.   x1,y1,x2,y2,LineWidth,width,height:integer;
  14. begin
  15.   size:=12;  {pixels}
  16.   angle:=20; {degrees}
  17.   pi:=3.14159;
  18.   GetLine(x1,y1,x2,y2,LineWidth);
  19.   if x1<0 then begin
  20.      beep;
  21.     PutMessage('Use the line tool (straight) to select a line first.');
  22.     exit;
  23.   end;
  24.   MoveTo(x1,y1);
  25.   LineTo(x2,y2);
  26.   KillRoi;
  27.   GetPicSize(width,height);
  28.   y1:=height-y1;
  29.   y2:=height-y2;
  30.   if LineWidth>1 then size:=size*LineWidth*0.5;
  31.   angle:=(angle/180)*pi;
  32.   dx:=x1-x2;
  33.   dy:=y1-y2;
  34.   if dx=0 then begin
  35.     if dy>=0 then theta:=pi/2 else theta:=3/2*pi
  36.   end else begin
  37.     theta:=arctan(dy/dx);
  38.     if dx<0 then theta:=theta+pi;
  39.   end;
  40.   moveto(x2,height-y2);
  41.   lineto(x2+size*cos(theta+angle),height-(y2+size*sin(theta+angle)));
  42.   moveto(x2,height-y2);
  43.   lineto(x2+size*cos(theta-angle),height-(y2+size*sin(theta-angle)));
  44. end;
  45.  
  46. macro 'Clear Outside [C]'
  47.  {Erase region outside current selection to background color.}
  48. begin
  49.   Copy;
  50.   SelectAll;
  51.   Clear;
  52.   RestoreRoi;
  53.   Paste;
  54.   KillRoi;
  55. end;
  56.  
  57. macro 'Change Colors';
  58. {
  59. Changes the value of pixels in the image that are in
  60. the current foreground color to the current background
  61. color. Use Undo if you don't like the result.
  62. }
  63. var
  64.   SavePixel,foreground,background:integer;
  65.  begin
  66.   SavePixel:=GetPixel(0,0);
  67.   MakeRoi(0,0,1,1);
  68.   Fill;
  69.   foreground:=GetPixel(0,0);
  70.   Clear;
  71.   background:=GetPixel(0,0);
  72.   PutPixel(0,0,SavePixel);
  73.   PutMessage('Pixels in the foreground color (',foreground:1,') will be changed to the background color (',background:1,').');
  74.   ChangeValues(foreground,foreground,background);
  75. end;
  76.  
  77. macro 'Change Values…';
  78. var
  79.   v1,v2:integer;
  80. begin
  81.   v1:=GetNumber('Change pixels with this value:',255);
  82.   v2:=GetNumber('to this value:',254);
  83.   ChangeValues(v1,v1,v2);
  84. end;
  85.  
  86. macro 'Fix Pseudocolors';
  87. begin
  88.   ChangeValues(0